//
//  CityView.m
//  A段项目
//
//  Created by 刘言松 on 15/10/13.
//  Copyright (c) 2015年 刘言松. All rights reserved.
//

#import "CityView.h"
#import "MapDesCItyModel.h"

 

@implementation CityView


-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    
    if (self) {
        
        [self addSubviews];
    }
    
    return self;
}

- (void)addSubviews{
    
    self.scroll = [[BaseScrollView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT )];
    [self addSubview:self.scroll];
   
    
    self.headImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT*0.3)];
    self.headImage.contentMode = UIViewContentModeScaleAspectFill;
    self.headImage.layer.masksToBounds = YES;
    self.headImage.image = [UIImage imageNamed:@"bundle_spot_edit_default_cover"];
    [self.scroll addSubview:self.headImage];
    
    
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, WIDTH * 0.18, WIDTH * 0.18)];
    CGPoint viewCenter = CGPointMake(self.headImage.center.x, self.headImage.height);
    view.center = viewCenter;
    view.layer.masksToBounds = YES;
    view.layer.cornerRadius = view.width/2;
    view.layer.borderWidth = WIDTH * 0.01;
    view.layer.borderColor = [[UIColor whiteColor]CGColor];
    view.backgroundColor = [UIColor colorWithRed:127/255.0 green:207/255.0 blue:218/255.0 alpha:1];
    [self.scroll addSubview:view];
    
    
    UIImageView *image = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"image_binder_poi_11_sl"]];
 
    image.center = view.center;
    [self.scroll addSubview:image];
    
    
    self.name = [[UILabel alloc]initWithFrame:CGRectMake(0, -HEIGHT, WIDTH, HEIGHT* 0.1)];
    self.name.center = image.center;
    self.name.y = image.y + image.height;
    self.name.textAlignment = NSTextAlignmentCenter;
    self.name.font = [UIFont boldSystemFontOfSize:20];
    [self.scroll addSubview:self.name];
    
   
    
    self.recommended_reason = [[UILabel alloc]initWithFrame:CGRectMake(0, -HEIGHT, WIDTH * 0.8, HEIGHT * 0.1)];
    self.recommended_reason.textAlignment = NSTextAlignmentCenter;
    self.recommended_reason.numberOfLines = 0;
    self.recommended_reason.center = self.name.center;
    self.recommended_reason.y = self.name.y + self.name.height;
    [self.scroll addSubview:self.recommended_reason];
    
    
    UILabel *centent = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT * 0.2)];
    centent.center = self.recommended_reason.center;
    centent.y = self.recommended_reason.y + self.recommended_reason.height;
    centent.text = @"基本信息";
    centent.textAlignment = NSTextAlignmentCenter;
    centent.font = [UIFont boldSystemFontOfSize:18];
    [self.scroll addSubview:centent];
    
    
    UILabel *descriptLabel = [[UILabel alloc]initWithFrame:CGRectMake(WIDTH * 0.05, centent.y + centent.height, WIDTH * 0.2, HEIGHT * 0.05)];
    descriptLabel.text = @"概况";
    descriptLabel.font = [UIFont boldSystemFontOfSize:17];
    [self.scroll addSubview:descriptLabel];
    
    
    self.descript = [[UILabel alloc]initWithFrame:CGRectMake(descriptLabel.x, descriptLabel.y + descriptLabel.height, WIDTH*0.9, 0)];
    self.descript.numberOfLines = 0;
    [self.scroll addSubview:self.descript];
    
    
    self.addressLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, -HEIGHT, WIDTH * 0.4,descriptLabel.height)];
    self.addressLabel.text = @"地址";
    self.addressLabel.font = [UIFont boldSystemFontOfSize:17];
    [self.scroll addSubview:self.addressLabel];

    
    self.address = [[UILabel alloc]init];
    self.address.numberOfLines = 0;
    [self.scroll addSubview:self.address];

    
    self.arrival_typeLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, -HEIGHT, WIDTH * 0.4, descriptLabel.height)];
    self.arrival_typeLabel.font = [UIFont boldSystemFontOfSize:17];
    self.arrival_typeLabel.text = @"到达方式";
    [self.scroll addSubview:self.arrival_typeLabel];

    
    self.arrival_type = [[UILabel alloc]init];
    self.arrival_type.numberOfLines = 0;
    [self.scroll addSubview:self.arrival_type];

    
    self.opening_timeLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, -HEIGHT, WIDTH * 0.4, descriptLabel.height)];
    self.opening_timeLabel.font = [UIFont boldSystemFontOfSize:17];;
    self.opening_timeLabel.text = @"开放时间";
    [self.scroll addSubview:self.opening_timeLabel];

    
    self.opening_time = [[UILabel alloc]init];
    self.opening_time.numberOfLines = 0;
    [self.scroll addSubview:self.opening_time];

    
    self.telLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, -HEIGHT, WIDTH * 0.4, descriptLabel.height)];
    self.telLabel.font = [UIFont boldSystemFontOfSize:17];
    self.telLabel.text = @"联系方式";
    [self.scroll addSubview:self.telLabel];

    
    self.tel = [[UILabel alloc]init];
    self.tel.numberOfLines = 0;
    [self.scroll addSubview:self.tel];

}

-(void)setModel:(MapDesCItyModel *)model
{
 

    _model = model;
 
    self.name.text = _model.name;
    
    self.recommended_reason.text = _model.recommended_reason;
    
    [self.headImage sd_setImageWithURL:[NSURL URLWithString:_model.cover] placeholderImage:[UIImage imageNamed:@"bundle_spot_edit_default_cover"]];
    
    self.descript.text = _model.descript;
    [self.descript sizeToFit];

    self.addressLabel.frame = CGRectMake(self.descript.x, self.descript.y + self.descript.height, self.descript.width, HEIGHT * 0.1);
    self.address.text = _model.address;
    self.address.frame = CGRectMake(self.addressLabel.x, self.addressLabel.y + self.addressLabel.height, WIDTH * 0.9, 0);
    [self.address sizeToFit];
    
    self.arrival_typeLabel.frame = CGRectMake(self.addressLabel.x, self.address.y + self.address.height, self.addressLabel.width, self.addressLabel.height);
    self.arrival_type.text = _model.arrival_type;

    self.arrival_type.frame = CGRectMake(self.arrival_typeLabel.x, self.arrival_typeLabel.y + self.arrival_typeLabel.height, WIDTH * 0.9, 0);
    [self.arrival_type sizeToFit];
    
    self.opening_timeLabel.frame = CGRectMake(self.arrival_typeLabel.x, self.arrival_type.y + self.arrival_type.height, self.arrival_typeLabel.width, self.arrival_typeLabel.height);
    self.opening_time.text = _model.opening_time;
    self.opening_time.frame = CGRectMake(self.opening_timeLabel.x, self.opening_timeLabel.y + self.opening_timeLabel.height, WIDTH * 0.9, 0);
    [self.opening_time sizeToFit];
    
    self.telLabel.frame = CGRectMake(self.opening_timeLabel.x, self.opening_time.y + self.opening_time.height, self.opening_timeLabel.width, self.opening_timeLabel.height);
    self.tel.text = _model.tel;
    if ([self.tel.text  isEqual: @""]) {
        self.tel.text = @"暂无";
    }
    self.tel.frame = CGRectMake(self.telLabel.x, self.telLabel.y + self.telLabel.height, WIDTH * 0.9, 0);
    [self.tel sizeToFit];
    
    self.scroll.contentSize = CGSizeMake(0, self.tel.y + self.tel.height);

//    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
//    btn.frame = CGRectMake(0, 0, 0, 0);
//    btn.width = self.headImage.width;
//    btn.height = self.headImage.height;
//    [btn addTarget:self action:@selector(clickAction:) forControlEvents:UIControlEventTouchUpInside];
//    self.headImage.userInteractionEnabled = YES;
//    [self.scroll addSubview:btn];
}

- (void)clickAction:(UIButton *)btn{
    
   // [_delegate push_album];
}

@end
